{extend name="index/public" /}

{block name="content"}
<form class="layui-form" action="" id="searchBox">
    <div class="layui-inline">
        <div class="layui-input-inline">
            {MyTag:game type='manage' /}
        </div>
    </div>
    <div class="layui-inline" style="width:232px;">
        <div class="my-btn my-btn-total">阶梯公式：10%|＜≤|50w|＞≥|20%</div>
    </div>
</form>

<table id="tableBox" lay-filter="tableBox"></table>
{/block}

{block name="css"}
{/block}

{block name="js"}
<script>
    layui.use('table', function(){
        var table = layui.table
            ,$ = layui.$
            ,form = layui.form
            ,load = null
            ,active = {
                reload: function () {
                    var game_id = $('#game_id').val();

                    table.reload('tableId', {
                        page: {curr: 1}
                        , where: {game_id:game_id}
                        ,height: 'full-100'
                    })
                },
            };

        //表格初始化
        table.render({
            elem: '#tableBox'
            ,height: 'full-100'
            ,url: '{:url("AuditCpInfo/index")}'
            ,page: true
            ,limit:20
            ,limits:[20,40,60,80]
            ,loading:true
            ,id:'tableId'
            ,done: function (res, curr, count) {
                layer.close(load);
                $('#layui-loading').hide();

                if(layui.data('auditCpInfoPrompt').onOff==undefined){
                    var statusObj = $('.layui-table-main>table>tbody tr:eq(0) td:eq(2)');
                    layer.tips('可即时编辑', statusObj, {tips: 3, tipsMore:true, time: 5000});
                    layui.data('auditCpInfoPrompt', {key: 'onOff',value: 1});
                }
            }
            ,cols: [[
                {field:'game_id', title: '游戏ID', width: 80, sort:true}
                ,{field:'game_name', title: '游戏名称' , width: 200}
                ,{field:'channel_rate', title: '渠道费率（公账）' , width: 200, sort:true, edit: 'text'}
                ,{field:'pay_rate', title: '结算比例（公账）' , width: 200, sort:true, edit: 'text'}
                ,{field:'pay_rate_private', title: '结算比例（私账）' , width: 200, sort:true, edit: 'text'}
            ]]
        });
//
        //监听搜索下拉菜单
        form.on('select(game_id)', function(data){
            load = layer.load();
            active['reload'].call(this)
        });

        //监听单元格编辑
        table.on('edit(tableBox)', function(obj){
            var value = obj.value //得到修改后的值
                ,data = obj.data //得到所在行所有键值
                ,field = obj.field
                ,params = {}
                ,load = layer.load();

            if(field=='channel_rate'){
                params = {game_id:data.game_id, channel_rate:value};
            }else if(field=='pay_rate'){
                params = {game_id:data.game_id, pay_rate:value};
            }else if(field=='pay_rate_private'){
                params = {game_id:data.game_id, pay_rate_private:value};
            }
            $.post('{:url("AuditCpInfo/edit")}',params, function(json){
                layer.close(load);
                if(json.code==0){
                    layer.msg(json.msg, {icon: 1, time:1000})
                }else{
                    layer.msg(json.msg, {icon: 0, time:1000});
                }
            }, 'JSON').error(function(){
                layer.close(load);
                layer.msg('连接超时，请联系后台管理员', {icon: 2, time:3000});
            });
        });
    });
</script>
{/block}